import api from "./api";
import { User } from "../types/index";

export interface RedeemCodeRequest {
  redeemcode: string;
}

export interface NicknameRequest {
  nickname: string;
}

/**
 * 使用兑换码续费 VIP
 * @param data 兑换码数据
 * @returns 续费结果
 */
export const renewVIP = async (
  data: RedeemCodeRequest
): Promise<{ message: string; data: string }> => {
  const response = await api.post<{ message: string; data: string }>(
    "/user/renewVIP",
    data
  );
  return response.data as { message: string; data: string };
};

/**
 * 设置用户昵称
 * @param data 昵称数据
 * @returns 更新结果
 */
export const setNickname = async (
  data: NicknameRequest
): Promise<{ message: string }> => {
  const response = await api.post<{ message: string }>(
    "/user/setNickName",
    data
  );
  return response.data as { message: string };
};

/**
 * 获取用户 VIP 到期时间
 * @returns VIP 到期时间
 */
export const getVIPExpireDate = async (): Promise<{ message: string }> => {
  const response = await api.get<{ message: string }>("/user/getVIPExpireDate");
  return response.data as { message: string };
};

/**
 * 获取用户 userInfo
 * @returns userInfo
 */
export const getUserInfo = async (): Promise<User> => {
  const response = await api.get<User>("/user/getUserInfo");
  return response.data as User;
};
